package MessageBeans;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import services.IConstants;

/**
 *
 * @author corneliugosa
 */
@MessageDriven(mappedName = "jms/ExamResponse", activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class ExamResponse implements MessageListener {
    
    public ExamResponse() {
    }
    
    @Override
    public void onMessage(Message message) {
        ObjectMessage msg = null;
        System.out.println("examResponse on message!");
        if(message instanceof ObjectMessage){
            try {
                msg = (ObjectMessage)message;
                int code = Integer.parseInt(msg.getStringProperty("code"));
                
                if(code==101){
                    System.out.println("Exam approved in ExamResponse");
                }
                
            } catch (JMSException ex) {
                Logger.getLogger(ExamResponse.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
